import {http} from "./http";
import {user} from "./user";

class EXAM{

    constructor(){
        this.paperID=/PaperId=([0-9]*)/.exec(decodeURIComponent(document.cookie))[1];
        this.series=/series=([0-9]*)/.exec(decodeURIComponent(document.cookie))[1];
        this.examID=/examId=([0-9]*)/.exec(decodeURIComponent(document.cookie))[1];
    }


    async getAnswers(){

        this.user=new user();
        await this.user.check();

        let response=await http.get(`http://xf.faxuan.net/ess/service/getpaper?paperId=${this.paperID}&series=${this.series}_answer`);
        let text=await response.text();

        let data= JSON.parse(text.split('\n')[2]);
        let index=window["examCount"]||50;
        data.forEach((d,i)=>{
            Reflect.deleteProperty(d,"score");
            if(i>=index) d.answerNo="";
        });


        let result=await (await http.post("http://xf.faxuan.net/ess/service/myexam/myExamAo!doCommitExam.do",{

            myExamAnswer:data,
            userAccount: this.user.userAccount,
            domainCode: this.user.domainCode,
            examId: this.examID,
            paperId: this.paperID,
            series: this.series,
            sid: this.user.sid
        })).text();

        console.log(result);
    }
}


export {EXAM};